<?php
//Report all errors except for E_STRICT, which refers to coding standards.
//By explicitly excluding E_STRICT, it's easy for code review tools to
//detect coding standards issues by removing the ~ and testing the program.
error_reporting(E_ALL & ~E_STRICT);
require_once 'Database.php';

logEvent(51, "AirIdentitySoapServer page after require_once directives)");
require_once 'GetNonce.php';
require_once 'authenticate.php';
require_once 'Authorize.php';

require_once 'AuthenticationRequest.php';
require_once 'AuthenticationResponse.php';
require_once 'AuthorizationRequest.php';
require_once 'AuthorizationResponse.php';
require_once 'AirIdentityException.php';
require_once 'SecureSoapServer.php';
require_once 'AirIdentityException.php';
require_once 'SecureSoapServer.php';
logEvent(51, "AirIdentitySoapServer page after require_once directives)");

function logEvent($level, $description)
{
	try 
	{
	$db = new Database();
	$db->connect();
	$db->logEvent("AirIdentitySoapServer.php", $level, $description);
	}
	catch (Exception $ee)
	{
		//if we can't log events, we're in serious trouble.
		//event logging capability is a prerequisite for this
		//service working.  don't do anything here.
	}
}

//Entry Point for SOAP Service
try
{
    $db = new Database();
    $db->connect();
    $db->logEvent('AirIdentitySoapServer entry', 51, 'Enter code block');
    ini_set("soap.wsdl_cache_enabled", "0");
    ini_set('soap.wsdl_cache_ttl',0);
    $options = array(
        'exceptions' => true,
        'trace' => 1,
        'cache_wsdl' => 'WSDL_CACHE_NONE', // http://www.php.net/manual/en/soapserver.soapserver.php
        'connection_timeout'=> 80 ,
        'encoding'=>'UTF-8');
    $server = new SecureSoapServer( 'AirIdentity.wsdl',$options);
    $functions = array('getNonce', 'authenticate', 'authorize');
    $server->addFunction($functions);
    $server->handle();
}
catch (SoapFault $ef)
{
    throw $ef;
}
catch (Exception $ee)
{
    throw new AirIdentityException('unhandled exception');
}		
?>